<?php

namespace App\Http\Controllers\Api;

use App\UserBalanceRecord;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class BalanceController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $data = UserBalanceRecord::latest()->where('user_id', Auth::id());
        if ($request->by_month) {
            $month = $request->month ? $request->month : date('m');
            $data = $data->whereMonth('created_at', $month);
        }
        return $data->get();
    }

    public function record(Request $request)
    {
        $orderBy = $request->order_by ? $request->order_by : $this->orderBy;
        $orderType = $request->order_type ? $request->order_type : $this->orderType;
        $pageSize = $request->page_size ? $request->page_size : $this->pageSize;
        $data = UserBalanceRecord::orderBy($orderBy, $orderType)->with('user');
        if ($request->user_id) {
            $data->where('user_id', $request->user_id);
        }
        return $data->paginate($pageSize);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\UserBalanceRecord  $userBalanceRecord
     * @return \Illuminate\Http\Response
     */
    public function show(UserBalanceRecord $userBalanceRecord)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\UserBalanceRecord  $userBalanceRecord
     * @return \Illuminate\Http\Response
     */
    public function edit(UserBalanceRecord $userBalanceRecord)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\UserBalanceRecord  $userBalanceRecord
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, UserBalanceRecord $userBalanceRecord)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\UserBalanceRecord  $userBalanceRecord
     * @return \Illuminate\Http\Response
     */
    public function destroy(UserBalanceRecord $userBalanceRecord)
    {
        //
    }
}
